package spring_annotation.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import spring_annotation.dao.BookDao;
import spring_annotation.pojo.Car;
import spring_annotation.pojo.Color;

@Configuration
@ComponentScan({
        "spring_annotation.service",
        "spring_annotation.dao",
        "spring_annotation.mvc.controller",
        "spring_annotation.pojo"
})
public class MainAutowiredConfig {

    @Primary            //首选
    @Bean("bookDao2")
    public BookDao bookDao(){
        BookDao bookDao = new BookDao();
        bookDao.setLabel("2");
        return bookDao;
    }

    @Bean
    public Color color(@Autowired Car car){     //@Autowired可以省略
        Color color = new Color();
        color.setCar(car);
        return color;
    }

}
